import Vue from 'vue'

//时间格式化-----------------------------------------------------------

//样式一 2018-05-28 17:25:06
Vue.filter("timeOne",function(n){
    var date = new Date(n*1000);
    var year = date.getFullYear();
    var month = (date.getMonth() + 1)<10?'0'+(date.getMonth() + 1):(date.getMonth() + 1);
    var day = date.getDate()<10?'0'+date.getDate():date.getDate();
    var hours = date.getHours()<10?'0'+date.getHours():date.getHours();
    var minute = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes();
    var second = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds();
    return year+'-'+month+'-'+day+' '+hours+':'+minute+":"+second
})

//样式二 2018-05-28
Vue.filter("timeTwo",function(n){
    var date = new Date(n*1000);
    var year = date.getFullYear();
    var month = (date.getMonth() + 1)<10?'0'+(date.getMonth() + 1):(date.getMonth() + 1);
    var day = date.getDate()<10?'0'+date.getDate():date.getDate();
    return year+'-'+month+'-'+day
})

//样式三 17:25:06
Vue.filter("timeThree",function(n){
    var date = new Date(n*1000);
    var hours = date.getHours()<10?'0'+date.getHours():date.getHours();
    var minute = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes();
    var second = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds();
    return hours+':'+minute+":"+second
})

//样式四 (今天/昨天/前天/2018-05-28) 17:25:06
Vue.filter("timeFor",function(n){
    var today=new Date();
    var todayYear=today.getFullYear();
    var todayYue=today.getMonth() + 1;
    var todayRi=today.getDate();
    var date = new Date(n*1000);
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hours = date.getHours()<10?'0'+date.getHours():date.getHours();
    var minute = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes();
    var second = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds();
    if(todayYear==year&&todayYue==month){
        if(day-todayRi==-1){
            return "昨天"+" "+hours+":"+minute+":"+second;
        }else if(day-todayRi==-2){
            return "前天"+" "+hours+":"+minute+":"+second;
        }else if(day-todayRi==0){
            return  "今天"+" "+hours+":"+minute+":"+second;
        }else{
            return  year+'-'+(month<10?'0'+month:month)+'-'+ (day<10?'0'+day:day)+" "+hours+":"+minute+":"+second;
        }
    }else{
        return  year+'-'+(month<10?'0'+month:month)+'-'+ (day<10?'0'+day:day)+" "+hours+":"+minute+":"+second;
    }
})

//电话格式化-----------------------------------------------------------

//样式一 188****3186
Vue.filter("phoneOne",function(n){
    var nToString=n.toString()//先转换为字符串
    var str=nToString.substring(3,nToString.length-4)
    return nToString.replace(str,"****")
})

//银行卡格式化-----------------------------------------------------------

//样式一 0068 (保留后四位)
Vue.filter("bankOne",function(n){
    var nToString=n.toString()//先转换为字符串
    var str=nToString.substring(nToString.length-4,nToString.length)
    return str
})

//样式二 **** **** **** 0068
Vue.filter("bankTwo",function(n){
    var nToString=n.toString()//先转换为字符串
    var str=nToString.substring(nToString.length-4,nToString.length)
    return "**** **** **** "+str
})

//身份证号码格式化-----------------------------------------------------------

//样式一 210****0560
Vue.filter("cardOne",function(n){
    var nToString=n.toString()//先转换为字符串
    var str=nToString.substring(3,nToString.length-4)
    return nToString.replace(str," **** **** ")
})